package com.haizhi.crm.api.util;

import com.haizhi.crm.common.model.PageQo;
import com.haizhi.crm.common.model.PageResponse;
import org.springframework.data.domain.Page;

/**
 * Created by chengmo on 2018/5/16.
 */
public class ResponseBuilder {

    public static <T> PageResponse get(Page<T> page, PageQo pageQo) {
        PageResponse response = PageResponse.success();
        response.setPageNo(pageQo.getPageNo());
        response.setPageSize(pageQo.getPageSize());
        response.setTotal(page.getTotalElements());
        response.setPayload(page.getContent());
        return response;
    }
}
